package {{configPackage}};

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

{{#useOas2}}
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
{{/useOas2}}
{{^useOas2}}
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
{{/useOas2}}
{{#useOptional}}
import java.util.Optional;
{{/useOptional}}

{{>generatedAnnotation}}
@Configuration
public class SwaggerDocumentationConfig {

    {{#useOas2}}
    @Bean
    public Docket customImplementation(){

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.basePackage("{{apiPackage}}"))
                    .build()
                {{#java8}}
                .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
                .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
                {{/java8}}
                {{#joda}}
                .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
                .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
                {{/joda}}
                {{#threetenbp}}
                .directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class)
                .directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)
                {{/threetenbp}}
                {{#useOptional}}
                .genericModelSubstitutes(Optional.class)
                {{/useOptional}}
                .apiInfo(apiInfo());
    }

    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("{{appName}}")
            .description("{{{appDescription}}}")
            .license("{{licenseInfo}}")
            .licenseUrl("{{licenseUrl}}")
            .termsOfServiceUrl("{{infoUrl}}")
            .version("{{appVersion}}")
            .contact(new Contact("","", "{{infoEmail}}"))
            .build();
    }
    {{/useOas2}}
    {{^useOas2}}
    @Bean
    public OpenAPI openApi() {
        return new OpenAPI()
            .info(new Info()
                .title("{{appName}}")
                .description("{{{appDescription}}}")
                .termsOfService("{{infoUrl}}")
                .version("{{appVersion}}")
                .license(new License()
                    .name("{{licenseInfo}}")
                    .url("{{licenseUrl}}"))
                .contact(new io.swagger.v3.oas.models.info.Contact()
                    .email("{{infoEmail}}")));
    }
    {{/useOas2}}

}
